import redis

#定义地址和端口
host = '127.0.0.1'
port = 6379

# host = '192.168.99.100'
# port = 6380

#建立redis连接
r = redis.Redis(host=host,port=port)

# # 有序集合
# r.zadd('myrank', {'car': 100})
# r.zadd('myrank', {'phone': 50})
# # r.delete('myrank')

# # 修改操作
# newscore = r.zincrby('myrank', -300, 'phone')
# print(newscore)

# 遍历有序集合
print(r.zrange('myrank', 0, -1, desc=True, withscores=True))

# 赋值
myrank = r.zrange('myrank', 0, -1, desc=True, withscores=True)

# r.expire('myrank', 60)

print(r.ttl('myrank'))

print(myrank[0][1])

# 生命周期的使用
# r.set('xing', 'xing')
# --expiretime  expiretime = expiretime - 1  0
# r.expire('xing', 10)
# print(r.get('xing'))

# list的使用 rpush
# r.lpush('testlist', 1)

# # r.delete('testlist')

# print(r.llen('testlist'))

# mylist = r.lrange('testlist', 0, r.llen('testlist'))

# print(mylist)

# #声明一个值
# r.set('test','123')

# #取值
# code = r.get('test')

# #转码
# code = code.decode('utf-8')

# print(code)

# r.sadd('testset', '活动')
# r.sadd('testset', '活动')
# r.sadd('testset', '特价')

# #查询
# myset = r.smembers("testset")
# print(myset)
# myset = list(myset)

# mytag = str(myset[0],"utf-8")
# print(mytag)
